package com.panopset.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import com.panopset.Strings;
import com.panopset.gui.container.TitledPanel;

/**
 * Data entry.
 * @deprecated going away, use ValidatingTextField instead.
 */
public class ValidatingDataEntry extends ValidatingField<String> {

    public final PVEID id;


    public String getValue() throws Exception {
        return getTf().getText();
    }
    /**
     * Panel.
     */
    private final TitledPanel p;

    /**
     * @return Titled panel.
     */
    public TitledPanel getTitledPanel() {
        return p;
    }

    /**
     * Update.
     */
    public String updateGui() {
        String s = super.updateGui();
        if (Strings.isPopulated(s)) {
            if (validate(s)) {
                getTitledPanel().setNormalHighlighting();
            } else {
                getTitledPanel().setAlertHighlighting();
            }
        } else {
            getTitledPanel().setAlertHighlighting();
        }
        UtilGUI.updateComponent(getTitledPanel().getPanel());
        return s;
    }


    /**
     * @param namedValue
     *            Named value.
     */
    ValidatingDataEntry(final PVEID pveId) {
        super(pveId.getLabel());
        id = pveId;
        p = new TitledPanel(id.getTip(), new GridBagLayout(), id.getTip());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1.0;
        p.getPanel().add(getTf(), gbc);
        getTf().setToolTipText(id.getTip());

    }

    @Override
    public boolean validate(String s) {
        return true;
    }

    @Override
    public void save() {
        // TODO Auto-generated method stub
        
    }
}
